package com.qf.servlet;

import com.qf.service.BookService;
import com.qf.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Hou
 * @version V1.0
 * @Project bookpro
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/13 17:21
 */
@WebServlet(name = "DeleteBookServlet",urlPatterns = "/deleteBook")
public class DeleteBookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        //通过bookID删除书籍
        String bookId = request.getParameter("bookId");

        BookService bookService = new BookServiceImpl();
        bookService.deleteBook(bookId);

//        删除之后 重新刷新列表
        response.sendRedirect(request.getContextPath() + "/bookList");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
